<?php
class BackupsController extends AppController {

	var $name = 'Backups';

	function index() {
		$this->Backup->recursive = 0;
		$this->set('backups', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid backup', true));
			$this->redirect($this->referer());
		}
		$this->set('backup', $this->Backup->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Backup->create();
			if ($this->Backup->save($this->data)) {
				$this->Session->setFlash(__('The backup has been saved', true));
				$this->redirect(array('controller' => 'audits', 'action' => 'view/'.$this->data['Backup']['audit_id']));
			} else {
				$this->Session->setFlash(__('The backup could not be saved. Please, try again.', true));
			}
		}
		$audits = $this->Backup->Audit->find('list');
		$this->set(compact('audits'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid backup', true));
			$this->redirect($this->referer());
		}
		if (!empty($this->data)) {
			if ($this->Backup->save($this->data)) {
				$this->Session->setFlash(__('The backup has been saved', true));
				$this->redirect(array('controller' => 'audits', 'action' => 'view/'.$this->data['Backup']['audit_id']));
			} else {
				$this->Session->setFlash(__('The backup could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Backup->read(null, $id);
		}
		$audits = $this->Backup->Audit->find('list');
		$this->set(compact('audits'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for backup', true));
			$this->redirect($this->referer());
		}
		if ($this->Backup->delete($id)) {
			$this->Session->setFlash(__('Backup deleted', true));
			$this->redirect($this->referer());
		}
		$this->Session->setFlash(__('Backup was not deleted', true));
		$this->redirect($this->referer());
	}
}
?>